<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">

<h:head> 
<script language="JavaScript"> 


    function SetFieldsValues(obj){
        
    	document.getElementById("f:fc").value = obj.value;
    	document.getElementById("f:fd").value = document.getElementById(obj.id.replace("flfc", "facDesc")).innerHTML;
    	document.getElementById("f:ft").value = document.getElementById(obj.id.replace("flfc", "facType")).innerHTML;
    	document.getElementById("f:ff").value = document.getElementById(obj.id.replace("flfc", "facFormula")).innerHTML;
    	document.getElementById("f:fu").value = document.getElementById(obj.id.replace("flfc", "facUnitPrice")).innerHTML;
    	document.getElementById("f:fi").value = obj.id.replace(":flfc", "").replace("dt01:", "");
    	if(isNaN(parseInt(document.getElementById("f:fi").value))) 
    	{
        	alert("Id = " + document.getElementById("f:fi").value);
        }
    	SetButtonValue(obj);
    } 

    function ResetFieldsValues(obj){
        
    	document.getElementById("f:fc").value = "";
    	document.getElementById("f:fd").value = "";
    	document.getElementById("f:ft").value = "";
    	document.getElementById("f:ff").value = "";
    	document.getElementById("f:fu").value = "";
    	document.getElementById("f:fi").value = -1;
    	SetButtonValue(obj);
    } 

    function SetButtonValue(obj){
        
    	if(document.getElementById("f:fi").value == -1) {
        	document.getElementById("f:btnAct").value = "Insert";
    	} else {
        	document.getElementById("f:btnAct").value = "Modify";
        } 
    } 

    function doPrint() { 
    	bdhtml=window.document.body.innerHTML; 
    	sprnstr=""; 
    	eprnstr="<!-- END -->"; 
//    	prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
//    	prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
		prnhtml = "Successful booking";
    	window.document.body.innerHTML=prnhtml; 
    	window.print(); 
    	}
</script> 
</h:head>


<body> 
<b>Facilities</b><br /><br /><br />

	<h:form id="f">
		<h:panelGrid columns="2" border="1">
			<h:panelGroup>
				<h:outputText value="Facility Code :" />
				<h:commandLink>help
					<rich:componentControl target="popup" operation="show" />
				</h:commandLink>
			</h:panelGroup>
			<h:panelGroup>
				<h:inputText id="fc" value="#{facilities.facilityCode}" label="Facility Code" required="true" />
				<h:message for="fc" />
			</h:panelGroup>
	
			
			<h:outputText value="Facilities Desc :" />
			<h:panelGroup>
				<h:inputText id="fd" value="#{facilities.facilityDesc}" label="Facility Descritpion" required="true" />
				<h:message for="fd" />
			</h:panelGroup>
			<h:outputText value="Facilities Type :" />
			<h:panelGroup>
				<h:selectOneMenu id="ft" value="#{facilities.facilityType}" label="Facility Type" >
					<f:selectItems value="#{facilityType.facTypes}"></f:selectItems>
				</h:selectOneMenu>
			</h:panelGroup>
			<h:outputText value="Cal. Formula :" />
			<h:panelGroup>
				<h:inputText id="ff" value="#{facilities.facilityFormula}" label="Facility Formula" required="true" />
				<h:messages errorClass="err" />
			</h:panelGroup>
			<h:outputText value="Fac. Unit Price :" />
			<h:panelGroup>
				<h:inputText id="fu" value="#{facilities.facilityUnitPrice}" label="Facility Unit Price" required="true" />
				<h:message for="fu" />
			</h:panelGroup>
		</h:panelGrid>
		<h:inputHidden id="fi" value="#{facilities.idFacilities}" />
		
		<h:commandButton id="btnAct" value="#{facilities.btnValue}" action="#{facilities.SaveFacility()}" style="font-size:26px;" >
					<f:actionListener type="cm367.FacilityValidator"></f:actionListener>
		</h:commandButton>
		<h:commandButton value="Reset" type="reset" onclick="ResetFieldsValues(this);" style="font-size:26px;"  /> 
	</h:form>
	
		<rich:popupPanel id="popup" modal="true"  autosized="true" >
			<f:facet name="header">
				<h:outputText value="Facilities Help" />
			</f:facet>
			<f:facet name="controls">
				<h:outputLink value="#" onclick="#{rich:component('popup')}.hide(); return false;">
					X
            	</h:outputLink>
			</f:facet>
			<h:panelGroup id="popupG" style="float:center" columns="1" border="1">
				<h:dataTable id="dt01" border="1" value="#{facilityList.facilitiesList}" var="flfl" headerClass="h1">
				
				
					<h:column id="Code">
						<h:commandButton  id="flfc" value="#{flfl.facilityCode}" onclick="SetFieldsValues(this);#{rich:component('popup')}.hide(); return false;">
						</h:commandButton>
						
						<f:facet name="header">
							<h:outputText value="Code" />
						</f:facet>
					</h:column>
					<h:column id="Description">
						<h:outputLabel id="facDesc" value="#{flfl.facilityDesc}" />
						<f:facet name="header">
							<h:outputText value="Description" />
						</f:facet>
					</h:column>
					<h:column id="Type">
						<h:outputLabel id="facType" value="#{flfl.facilityType}" />
						<f:facet name="header">
							<h:outputText value="Type" />
						</f:facet>
					</h:column>
					<h:column id="Formula">
						<h:outputLabel id="facFormula" value="#{flfl.facilityFormula}" />
						<f:facet name="header">
							<h:outputText value="Cal. Formula" />
						</f:facet>
					</h:column>
					<h:column id="UnitPrice">
						<h:outputText id="facUnitPrice" value="#{flfl.facilityUnitPrice}"  align="right" />
						<f:facet name="header">
							<h:outputText value="Unit Price" />
						</f:facet>
					</h:column>
				</h:dataTable>
			</h:panelGroup>
		</rich:popupPanel>
	
</body> 
</html>
